import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text,Input } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import Hearder from './hearder'
import './card.scss'

export default class Index extends Component {
  constructor(props) {
    super(props)
    this.state = {
    	isload:1,
    	list:'',
    	couponlist:[],
		cindex:0,
		appmark:CommonJs.getmark()
    }
  }
  config = {
    navigationBarTitleText:'加载中'
  }
  open(url,type){
    CommonJs.openTo(url)
  }
  componentWillMount () {
	if(this.state.appmark=='xjzb'){
		Taro.setNavigationBarTitle({
			title:'易会员'
		  })
	}
	else{
		Taro.setNavigationBarTitle({
			title:'会员权益'
		  })
	}
		this.getcoupon()
		this.getqy()
  }
  componentDidShow () {

  }
 	getcoupon(){
  	var url="/crm/papi/v1.9/coupon";
  	var dates={
  		"couponStatus.in":"RECEIVED",
  		size:10,
  		page:0
  	}
  	var _this=this
  	CommonJs.ajaxRequest(url,dates,'GET',function(res){
		_this.setState({
	      couponlist:res.data.list
	    })
  	},"wfw")
  }
	getqy(){
  	var url="/crm/papi/v1.9/member-marketing/memberDetails/"+Taro.getStorageSync('shopId') 
  	var _this=this
  	CommonJs.ajaxRequest(url,'','GET',function(res){
  		var index=0
			for(var i=0;i<res.data.length;i++){
				if(res.data[i].memberStatus==1){
					index=i;
				}
			}
			_this.setState({
	      list:res.data,
	      cindex:index
	    })
  	},"wfw")
  }
  
  render () {
  	const result = this.state.couponlist 
  	const list = this.state.list 
  	const info=this.state.list[this.state.cindex]
    return (
      <View className='page'>
      	<View className='card-page'>
      			<View className='card-list'>
      					<View className='card-dl'>
      						<View className='card-dt'>
      							<Image className="cat-img" mode="widthFix" src={CommonJs.getlogo()}></Image>
      						</View>
      						<View  className='card-dd'>
      							<Text className='card-h3'>{info.levelName}</Text>
      							<Text className='card-price'>享受群内消费{info.discount?info.discount/10:'10'}折优惠</Text>
      						</View>
      					</View>
      					<View className='card-info'>
      						<Text className='card-fr'>有效期:长久有效</Text>
      						<Text className='card-qun' style={list.length>0?'':'display:none'}>每月权益:{info.discount/10}折券*{info.num}张</Text>
      					</View>
      			</View>
      			<View className='card-qy'>
      					<View className='card-qy-tit'>会员权益</View>
      					<View className='card-qy-con' style={list.length>0?'':'display:none'}>
      						<View className='card-qy-ul card-qy-ults'>
      							<View className='card-qy-li'>会员等级</View>
      							<View className='card-qy-li'>会员条件</View>
      							<View className='card-qy-li card-qy-lits'>每月权益</View>
      						</View>
      						{list.map((item, index) => (  
      						<View className={item.memberStatus==1?'card-qy-ul card-qy-ults01':'card-qy-ul'}>
      							<View className='card-qy-li'>{item.levelName}</View>
      							<View className='card-qy-li'>{item.openingConditions}</View>
      							<View className='card-qy-li card-qy-lits'>{item.discount/10}折券*{item.num}张</View>
      						</View>
      						))} 
      					</View>
      					<View className='card-qy-con' style={list.length==0?'':'display:none'}>
      						<View className='nodate'>该商家暂时没有开通会员功能,敬请期待</View>
      					</View>
      			</View>
      			<View className='card-qy' style={result.length>0?'':'display:none'}>
      					<View className='card-qy-tit'>使用券到店消费</View>
      					<View className='card-qy-con'>
      							
      							{result.map((item, index) => (  
      							<View className='yhq-dl'>
			        				<View className="yhq-dt" onClick={this.openxq.bind(this,item.mallId,item.id)}>
			        						<View style={item.publish.couponType.indexOf('DISCOUNT')>=0?'':'display:none'}>
				        						<Text className="jg">{item.publish.ruleFavourData/10}</Text>
				        						<Text className="tb"> 折</Text>
				        						</View>
				        						<View style={item.publish.couponType.indexOf('DISCOUNT')>=0?'display:none':''}>
				        						<Text className="tb">¥</Text>
				        						<Text className="jg">{item.publish.ruleFavourData/100}</Text>
				        					</View>
			        						<Text className="tj">{item.publish.summary}</Text>
			        				</View>
			        				<View className="yhq-dd" onClick={this.openxq.bind(this,item.mallId,item.id)}>
			        					<Text className="yhq-sy">去使用</Text>
			        				</View>
			        			</View>
			        			))}
			        			
      					</View>
      			</View>
      			<View className='card-btn card-btnts' style={this.state.cindex==0&&list.length>0?'':'display:none'} onClick={this.open.bind(this,'/pages/card/cardadd')}>开通会员</View>
      	</View>
      
      </View>
    )
  }
}
